<template>
  <div class="user">
    <!-- top -->
    <div class="top">
      <!-- top1 -->
      <div class="top1">
        <div class="top1-left">
          <div class="top1-name">{{ userInfo.nickname }}</div>
          <div class="left-txt">{{ userInfo.intro }}</div>
        </div>
        <!-- 有头像 -->
        <img
          v-if="userInfo.avatar"
          :src="baseUrl + userInfo.avatar"
          class="top1-right"
          @click="goInfo"
        />
        <!-- 没头像 -->
        <img
          v-else
          src="@/assets/logo.png"
          class="top1-right"
          alt=""
          @click="goInfo"
        />
      </div>
      <!-- top2 -->
      <ul class="top2">
        <!-- 累计答题 -->
        <li class="top2-item">
          <div class="top2-num">298</div>
          <div class="top2-txt">累计答题</div>
        </li>
        <!-- 收藏题目 -->
        <li class="top2-item">
          <div class="top2-num">98</div>
          <div class="top2-txt">收藏题目</div>
        </li>
        <!-- 我的错题 -->
        <li class="top2-item">
          <div class="top2-num">198</div>
          <div class="top2-txt">我的错题</div>
        </li>
        <!-- 正确率 -->
        <li class="top2-item">
          <div class="top2-num">298</div>
          <div class="top2-txt">正确率</div>
        </li>
      </ul>
      <!-- top3 -->
      <div class="top3">
        <!--  <van-cell is-link center> -->
        <!-- <template #icon> -->
        <!-- <i class="iconfont pr12">&#xe64d;</i> -->
        <!-- </template> -->
        <!-- 我的岗位 -->
        <!-- <template #title> -->
        <!-- <div class="title">我的岗位</div> -->
        <!-- </template> -->
        <!-- 产品经理 -->
        <!--  <template #default> -->
        <!-- <div class="title">产品经理</div> -->
        <!-- </template> -->
        <!-- </van-cell> -->
        <user-cell
          @click="$router.push('/home/editInfo?type=position')"
          title="我的岗位"
          :value="userInfo.position"
          icon="&#xe64d;"
        ></user-cell>
      </div>
    </div>
    <!-- middle -->
    <div class="content">
      <div class="middle">
        <h3 class="middle-title">面经数据</h3>
        <ul class="middle-data">
          <!-- 昨日阅读 -->
          <li class="middle-item">
            <div class="item1">昨日阅读<span>+300</span></div>
            <div class="item2">17</div>
            <div class="item3">阅读总数</div>
          </li>
          <!-- 昨日获赞 -->
          <li class="middle-item">
            <div class="item1">昨日获赞<span>+300</span></div>
            <div class="item2">17</div>
            <div class="item3">获赞总数</div>
          </li>
          <!-- 昨日新增 -->
          <li class="middle-item">
            <div class="item1">昨日新增<span>+300</span></div>
            <div class="item2">17</div>
            <div class="item3">评论总数</div>
          </li>
        </ul>
      </div>
      <!-- bottom -->
      <div class="bottom">
        <user-cell title="我的面经分享" value="21" icon="&#xe655;"></user-cell>
        <user-cell title="我的消息" value="98" icon="&#xe656;"></user-cell>
        <user-cell title="收藏的题库" value="32" icon="&#xe654;"></user-cell>
        <user-cell title="收藏的企业" value="32" icon="&#xe648;"></user-cell>
        <user-cell title="我的错题" value="123" icon="&#xe64f;"></user-cell>
        <user-cell
          title="收藏的面试经验"
          value="166"
          icon="&#xe649;"
        ></user-cell>
      </div>
    </div>
  </div>
</template>

<script>
// 解决背景色问题 1：进入页面时设置body背景色 2：离开页面时，还原body背景色
import userCell from './userCell'
// 导入mapState
import { mapState } from 'vuex'
// import { auInfo } from '@/api/user.js'
// import { getToken } from '@/utils/local.js'
export default {
  data () {
    return {
      baseUrl: process.env.VUE_APP_URL
    }
  },
  methods: {
    // 点击头像跳转到userInfo页面编辑
    goInfo () {
      this.$router.push('/home/userInfo')
    }
  },
  // 组件
  components: {
    userCell
  },
  computed: {
    // ...mapState(['希望取出store内的state的属性名'])
    ...mapState(['userInfo', 'isLogin'])
  },
  created () {},
  mounted () {
    document.body.style.backgroundColor = '#1f1f1f'
    // if (!this.isLogin) {
    //   if (getToken()) {
    //     auInfo()
    //       .then(res => {
    //         // 存储到vuex
    //         this.$store.commit('setUserInfo', res.data.data)
    //         this.$store.commit('setIsLogin', true)
    //         window.console.log(res)
    //       })
    //       .catch(err => {
    //         window.console.log(err)
    //       })
    //   } else {
    //     this.$router.push('/login')
    //   }
    // }
  },
  beforeDestroy () {
    document.body.style.backgroundColor = '#fff'
  }
}
</script>

<style lang="less" scoped>
.user {
  // top
  .top {
    padding: 0 @p15;
    // 渐变色没些
    background: linear-gradient(45deg, #ce0031, #b8002c);
    position: relative;
    .top1 {
      padding: 31px 0 28px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .top1-left {
        .top1-name {
          font-size: 21px;
          font-family: PingFangSC, PingFangSC-Semibold;
          font-weight: 600;
          text-align: left;
          color: #fff;
          line-height: 30px;
          letter-spacing: 0px;
        }
        .left-txt {
          opacity: 0.7;
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          text-align: left;
          color: #fff;
          line-height: 16px;
          letter-spacing: 0px;
        }
      }
      .top1-right {
        width: 50px;
        height: 50px;
        border: 3px solid rgba(255, 255, 255, 0.38);
        border-radius: 50%;
      }
    }
    .top2 {
      display: flex;
      justify-content: space-between;
      .top2-item {
        text-align: center;
        .top2-num {
          font-size: 21px;
          font-family: PingFangSC, PingFangSC-Semibold;
          font-weight: 700;
          text-align: center;
          color: #fff;
          line-height: 24px;
          letter-spacing: 0px;
        }
        .top2-txt {
          padding-top: 6px;
          padding-bottom: 55px;
          opacity: 0.7;
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          text-align: center;
          color: #fff;
          line-height: 16px;
          letter-spacing: 0px;
        }
      }
    }
    .top3 {
      position: absolute;
      bottom: -16px;
      left: 0;
      width: 100%;
      padding: 0 @p15;
      .title {
        font-size: 14px;
        font-family: PingFangSC, PingFangSC-Regular;
        font-weight: 400;
        text-align: left;
        color: #181a39;
        line-height: 20px;
        letter-spacing: 0px;
      }
    }
  }
  // middle
  .content {
    background-color: #1f1f1f;
    padding: 26px @p15 0;
    .middle {
      padding: 19px 16px 16px;
      background-color: #fff;
      .middle-title {
        padding-bottom: 17px;
        font-size: 14px;
        font-family: PingFangSC, PingFangSC-Semibold;
        font-weight: 600;
        text-align: left;
        color: #181a39;
        line-height: 20px;
        letter-spacing: 0px;
      }
      .middle-data {
        display: flex;
        justify-content: space-between;
        .middle-item {
          text-align: center;
          font-size: 12px;
          .item1 {
            font-size: 12px;
            font-family: PingFangSC, PingFangSC-Regular;
            font-weight: 400;
            text-align: center;
            color: #b4b4bd;
            line-height: 14px;
            letter-spacing: 0px;
            span {
              color: #00b8d4;
            }
          }
          .item2 {
            padding: 10px 0;
            font-size: 21px;
            font-family: DINAlternate, DINAlternate-Bold;
            font-weight: 700;
            text-align: center;
            color: #181a39;
            line-height: 24px;
            letter-spacing: 0px;
          }
          .item3 {
            font-size: 12px;
            font-family: PingFangSC, PingFangSC-Regular;
            font-weight: 400;
            text-align: center;
            color: #545671;
            line-height: 16px;
            letter-spacing: 0px;
          }
        }
      }
    }
  }
}
</style>
